package JavaSE.demoSE789;

public class test {
    public static int binarysearch(int[] array,int key) {
        int left = 0;
        int right = array.length-1;
        while (left<=right){
            int mid = (left+right)>>>1;
            if (array[mid] < key) {
                left = mid + 1;
            }else if (array[mid] == key){
                return mid;
            }else {
                right=mid-1;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        int[] array = {1,6,9,11,16,17,19,36};
        int ret = binarysearch(array,17);
        if (ret==-1){
            System.out.println("没有你所要找的关键字！");
        }else {
            System.out.println("你所要找的下标为：" + ret);
        }
    }
}
